<?php
/***********************************************************************

  Copyright (C) 2002-2008  PunBB

  This file is part of PunBB.

  PunBB is free software; you can redistribute it and/or modify it
  under the terms of the GNU General Public License as published
  by the Free Software Foundation; either version 2 of the License,
  or (at your option) any later version.

  PunBB is distributed in the hope that it will be useful, but
  WITHOUT ANY WARRANTY; without even the implied warranty of
  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  GNU General Public License for more details.

  You should have received a copy of the GNU General Public License
  along with this program; if not, write to the Free Software
  Foundation, Inc., 59 Temple Place, Suite 330, Boston,
  MA  02111-1307  USA

************************************************************************/

define('PUN_ROOT', './');
require PUN_ROOT.'include/common.php';

if ($pun_user['g_read_board'] == '0')
	message($lang_common['No view']);

require PUN_ROOT.'header.php';
?>

<div id="punviewtopic" class="pun">

<?php

require PUN_ROOT.'include/parser.php';

$bg_switch = true;	// Used for switching background color in posts
$feeditem_count = 0;	// Keep track of feeditem numbers

$result = $db->query('SELECT i.userid, i.timestamp, i.title, i.link, i.author, i.description, u.use_avatar, u.username FROM '.$db->prefix.'feeditems AS i INNER JOIN '.$db->prefix.'users AS u ON u.id=i.userid ORDER BY timestamp DESC') or error('Unable to fetch feeditem info', __FILE__, __LINE__, $db->error());

// If there are feeds.
if ($db->num_rows($result))
{
	while ($cur_feeditem = $db->fetch_assoc($result))
	{
		$feeditem_count++;
		$user_avatar = '';
		$user_info = array();
		$username = '';

		$username = '<a href="profile.php?id='.$cur_feeditem['userid'].'">'.pun_htmlspecialchars($cur_feeditem['username']).'</a>';
		if ($pun_config['o_avatars'] == '1' && $cur_feeditem['use_avatar'] == '1' && $pun_user['show_avatars'] != '0')
		{
			if ($img_size = @getimagesize($pun_config['o_avatars_dir'].'/'.$cur_feeditem['userid'].'.gif'))
				$user_avatar = '<img src="'.$pun_config['o_avatars_dir'].'/'.$cur_feeditem['userid'].'.gif" '.$img_size[3].' alt="" />';
			else if ($img_size = @getimagesize($pun_config['o_avatars_dir'].'/'.$cur_feeditem['userid'].'.jpg'))
				$user_avatar = '<img src="'.$pun_config['o_avatars_dir'].'/'.$cur_feeditem['userid'].'.jpg" '.$img_size[3].' alt="" />';
			else if ($img_size = @getimagesize($pun_config['o_avatars_dir'].'/'.$cur_feeditem['userid'].'.png'))
				$user_avatar = '<img src="'.$pun_config['o_avatars_dir'].'/'.$cur_feeditem['userid'].'.png" '.$img_size[3].' alt="" />';
		}
		else
			$user_avatar = '';

		// Switch the background color for every message.
		$bg_switch = ($bg_switch) ? $bg_switch = false : $bg_switch = true;
		$vtbg = ($bg_switch) ? ' roweven' : ' rowodd';
?>

<div class="blockpost<?php echo $vtbg ?>">
	<div class="box">
		<div class="inbox">
			<div class="postleft">
				<dl>
					<dt><strong><?php echo $username ?></strong></dt>
					<dd class="postavatar"><?php echo $user_avatar ?></dd>
				</dl>
			</div>
			<div class="postright">
				<div name="convert" class="postmsg">
					<p><?php echo '<h1><a target="_blank" href="'.pun_htmlspecialchars($cur_feeditem['link']).'">'.pun_htmlspecialchars($cur_feeditem['title']).'</a></h1>';?></p>
					<?php if ($cur_feeditem['author'] != '') echo '<p>'.$lang_common['Author'].':'.pun_htmlspecialchars($cur_feeditem['author']).'</p>';?>
					<p><?php echo aggregator_filter_xss($cur_feeditem['description']);?></p>
				</div>
			</div>
		</div>
	</div>
</div>

<?php
	}
}
else
{
	message('There is no feeds yet.');
}
?>

</div>

<?php
require PUN_ROOT.'footer.php';


/**
 * Safely render HTML content, as allowed.
 */
function aggregator_filter_xss($value)
{
	return filter_xss($value, array('b', 'br', 'dd', 'dl', 'dt', 'em', 'i', 'li', 'ol', 'p', 'strong', 'u', 'ul', 'img'));
}

?>
